<template>
	<view>
		<view class="errormsgDiv" v-if="nodata">
			<view class="errormsg">\（￣︶￣）/</view>
			<view class="errormsg2">没有相关评价</view>
		</view>

		<view  v-else>
			<view class="eva-box" :key="index" v-for="(item, index) in items">
				<image class="portrait" :src="item.user.avatarUrl" mode="aspectFill"></image>
				<view class="right">
					<text class="name">{{ item.user.nickname }}</text>
					<view class="name"><uni-rate disabled="true" :value="item.score / 20"></uni-rate></view>
					<text class="con">{{ item.content }}</text>
					<view class="cu-form-group" style="padding: 0;" v-if="item.pics && item.pics.length > 0">
						<view class="grid col-4 grid-square flex-sub">
							<view class="bg-img" v-for="(img, index2) in item.pics" :key="index2" @tap="ViewImage(item.pics, img)">
								<image :src="img + '?imageView2/2/w/200'" mode="aspectFill"></image>
							</view>
						</view>
					</view>

					<view class="bot">
						<text class="time">{{ item.time_tran }}</text>
					</view>
				</view>
			</view>
		</view>
	</view>
</template>

<script>
import beeApp from '../../beeApp.js';
import uniRate from '@/components/uni-rate/uni-rate.vue';
export default {
	components: { uniRate },
	data() {
		return {
			items: [],
			page: 1,
			mounted: 0,
			nodata: 0,
			loadding: 0,
			userInfo: {},
			lastpage: 0
		};
	},
	onLoad(option) {
		beeApp.getUserInfo(userInfo => {
			this.userInfo = userInfo;
			this.getList();
		});
	},

	onReachBottom() {
		this.getList();
	},
	onPullDownRefresh() {
		this.getList(1);
		uni.stopPullDownRefresh();
	},
	onShow: function() {},
	methods: {
		ViewImage(imgList, image) {
			uni.previewImage({
				urls: imgList,
				current: image
			});
		},
		getList: function(reload = 0) {
			var _this = this;
			if (reload == 1) {
				this.page = 1;
				this.loadding = 0;
				this.lastpage = 0;
				this.items = [];
			}
			var params = {
				page: this.page,
				to_user_id: this.userInfo.user_id,
				fields: 'id,content,user,time_tran,pics,score',
				limit: 10,
				type: 'daoJia'
			};
			if (this.loadding == 1 || this.lastpage == 1) {
				return false;
			}
			_this.loadding = 1;
			beeApp.api('/sns/comment/get', params, function(res) {
				_this.loadding = 0;
				if (res.code != 200) {
					beeApp.alert(res.msg);
					return;
				}
				// console.log(res);
				if (res.data.list.length === 0) {
					_this.lastpage = 1;
				}

				var items = _this.items;
				_this.items = items.concat(res.data.list);
				_this.page++;
				if (_this.items.length === 0) {
					_this.nodata = 1;
				} else {
					_this.nodata = 0;
				}
			});
		}
	}
};
</script>
<style lang="scss">
.eva-box {
	display: flex;
	padding: 20upx;
	    background: #fff;
    margin-bottom: 20upx;

	.portrait {
		flex-shrink: 0;
		width: 80upx;
		height: 80upx;
		border-radius: 100px;
	}
	.right {
		flex: 1;
		display: flex;
		flex-direction: column;
		font-size: $font-base;
		color: $font-color-base;
		padding-left: 26upx;
		.con {
			font-size: $font-base;
			color: $font-color-dark;
			padding: 20upx 0;
		}
		.bot {
			display: flex;
			justify-content: space-between;
			font-size: $font-sm;
			color: $font-color-light;
		}
	}
}
</style>
